<?php


namespace app\admin\validate;

use think\Validate;
class AdminValidate2 extends Validate
{
    protected $rule=[
        'admin_roles'=>'require|checkRoles',
        'end_num'=>'require|number',
        'end_time'=>'require|date',
        'admin_name'  => 'require|length:2,15',
        'admin_password'   => 'require|alphaNum',
        'admin_password2'   => 'require|alphaNum|confirm:admin_password'
    ];
    protected $field = [
        'admin_roles'  =>'角色',
        'end_num'=>'程序数量',
        'end_time'=>'账户过期时间'
    ];
    protected $message =[
        'admin_name.require' => '账户名称不能为空',
        'admin_name.length' =>'账户名称必须2-15字符',
        'admin_password.require' =>'密码不能为空',
        'admin_password.alphaNum'   => '密码只能字母和数字',
        'admin_password2.require' =>'确认密码不能为空',
        'admin_password2.alphaNum'   => '确认密码只能字母和数字',
        'admin_password2.confirm' => '密码和确认密码不一致',
    ];
    protected $scene =[
      'update_admin_roles3' =>['admin_password','admin_password2']
    ];
    protected function checkRoles($val){
        if(in_array($val,[1,2,3])){
            return true;
        }else{
            return '角色选择错误';
        }
    }
}